package com.lzx.iteam.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.lzx.iteam.R;
import com.lzx.iteam.bean.AttendanceData;
import com.lzx.iteam.bean.DateData;

import java.util.ArrayList;

/**
 * Created by Megan on 16/4/9.
 */
public class AttendanceCountMonthAdapter extends BaseAdapter {

    private Context mContext;
    private ArrayList<DateData> dateDatas;

    public AttendanceCountMonthAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void bindData(ArrayList<DateData> dateDatas) {
        this.dateDatas = dateDatas;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return dateDatas==null?0:dateDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return dateDatas==null?null:dateDatas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.attendace_count_month_list_item_layout, null);
            holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.tv_attendance_count_month);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        DateData date = dateDatas.get(position);
        holder.text.setText(String.format("%s 年 %s 月",date.getYear(),date.getMonth()));
        return convertView;
    }

    class ViewHolder {
        TextView text;
    }
}
